package com.dfbz.bigdata.modules.system.shop.order.controller;


import com.dfbz.bigdata.common.utils.R;
import com.dfbz.bigdata.modules.system.shop.order.dto.UanddOrdersDto;
import com.dfbz.bigdata.modules.system.shop.order.services.UanddOrdersServiceMini;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("udorder")
@Slf4j
public class UanddOrdersControllerMini {

    @Autowired
    private UanddOrdersServiceMini ordersService;




//    查询订单分页
    @GetMapping
    public R<List<UanddOrdersDto>> getOrderList(String udOdNum, int currentPage, int pagesizes){

        List<UanddOrdersDto> uanddOrderList = ordersService.getUanddOrderList(udOdNum, currentPage, pagesizes);

        for (UanddOrdersDto uanddOrdersDto : uanddOrderList) {

            uanddOrdersDto.setUserMsg("用户姓名: "+uanddOrdersDto.getUserName()+",手机号: "+uanddOrdersDto.getUserPhone());
            uanddOrdersDto.setDesignerMsg("设计师姓名: "+uanddOrdersDto.getDesignerName()+
                           ",设计师描述: "+uanddOrdersDto.getDesignerText()+
                            ",设计师风格: "+uanddOrdersDto.getDesignerStyle());
        }
        return R.success(uanddOrderList);
    }

    @GetMapping("/total")
    public R<Integer> getDicTotal(){

        return R.success(ordersService.getTotal());

    }


//    @GetMapping
//    public R<List<UanddOrdersDto>> getorderlist(String udOdNum) {
//        log.info("*******{}",udOdNum);
//
////      条件构造器 模糊查询 加分页
//        LambdaQueryWrapper<UanddOrders> lqw=new LambdaQueryWrapper<>();
//        lqw.like(!udOdNum.isEmpty(),UanddOrders::getUdOdNum,udOdNum);
//        List<UanddOrders> uanddOrders = ordersService.list(lqw);
//
//        List<UanddOrdersDto> uanddOrdersDtos=new ArrayList<>();
////           遍历订单列表
//        for (UanddOrders order : uanddOrders) {
////            new 出dto对象
//            UanddOrdersDto uanddOrdersDto=new UanddOrdersDto();
////            得到下单用户id  设计师id  保险id
//            Long userId = order.getUserId();
//            Long designId = order.getUdOdDesignerId();
//
////            查询到下单用户的信息
//            R<UserDesignerandpersonal> userR = userDesignerApi.findById(userId);
////            查询设计师信息
//            R<UserDesignerandpersonal> designerR = userDesignerApi.findById(designId);
//
////            order对象中重复属性copy到dto
//            BeanUtils.copyProperties(order,uanddOrdersDto);
//
////            用户信息赋值到dto
//            UserDesignerandpersonal user = userR.getData();
//            String userMsg="姓名:"+user.getUserName()+",手机号:"+user.getUserPhone();
//            uanddOrdersDto.setUserMsg(userMsg);
//
////            设计师信息赋值到dto
//            UserDesignerandpersonal design = designerR.getData();
//            String designMsg="设计师姓名:"+design.getUserName()+",设计师手机号:"+design.getUserPhone()
//                    +",设计师描述:"+design.getUserText()+",设计师风格:"+design.getUserDesignerStyle();
//            uanddOrdersDto.setDesignerMsg(designMsg);
//
////            保险信息
//
////            add到list
//            uanddOrdersDtos.add(uanddOrdersDto);
//
//        }
//
//        return R.success(uanddOrdersDtos);
//    }


    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable Long id){
        boolean b = ordersService.removeById(id);
        if (b){
            return R.success("删除成功");
        }
        else return  R.error("系统繁忙");

    }


}
